export { }
interface A {
	a: string
	b: number
	c: boolean
}
type PartialA = Partial<A>
let a: PartialA = {
	a: '', c: true
}

interface Company {
	id: number
	name: string
}
interface Person {
	id: number
	name: string
	compangy: Company
}
type DeepPartial<T> = {
	[U in keyof T]?: T[U] extends object ? DeepPartial<T[U]> : T[U]
}
type PartialPerson = Partial<Person>
type R2 = DeepPartial<Person>
let c1: PartialPerson = {
	id: 1,
	compangy: {
		id: 1,
		name: "123"
	}
}

namespace a1 {
	interface Person {
		name: string;
		age?: number;
	}
	type RequiredPerson = Required<Person>
	let p: RequiredPerson = {
		name: 'jack',
		age: 1
	}

}
namespace a2 {
	interface Person {
		name: string;
		age: number;
		gender?: 'male' | 'female';
	}
	//type Readonly<T> = { readonly [P in keyof T]: T[P] };
	let p: Readonly<Person> = {
		name: 'jack',
		age: 10,
		gender: 'male'
	}
	p.age = 11;
}
namespace a3 {
	interface Person {
		name: string;
		age: number;
		gender: number;
	}
	let person: Person = { name: 'jack', age: 11, gender: 1 }
	type Pick<T, K extends keyof T> = {
		[P in K]: T[P]
	}
	type PickPerson = Pick<Person, 'name' | 'age'>
}

namespace d {
	/**
 * Construct a type with a set of properties K of type T
 */
	type Record<K extends keyof any, T> = {
		[P in K]: T;
		// []表示任意属性
		// [key:string]:string
		// [key:number]:number
	};
	function mapObject<K extends string | number, T, U>(obj: Record<K, T>, map: (x: T) => U): Record<K, U> {
		let result: any = {};
		for (const key in obj) {
			result[key] = map(obj[key]);
		}
		return result;
	}
	let names = { 0: 'hello', 1: 'world' };
	let lengths = mapObject<string | number, string, number>(names, (s: string) => s.length);
	console.log(lengths);//{ '0': 5, '1': 5 }
	type Point = 'x' | 'y';
	type PointList = Record<Point, { value: number }>
	const cars: PointList = {
		x: { value: 10 },
		y: { value: 20 },
	}

}